package net.thread;

import java.io.File;
import java.io.FileInputStream;
import java.security.DigestInputStream;
import java.security.MessageDigest;

public class InstanceCallbackDigest implements Runnable
{
	private File file;
	private InstanceCallbackDigestUserInterface callback;
	public InstanceCallbackDigest(File input,InstanceCallbackDigestUserInterface callback)
	{
		this.file = input;
		this.callback = callback;
	}
	@Override
	public void run()
	{
		try
		{
			FileInputStream in = new FileInputStream(file);
			MessageDigest sha = MessageDigest.getInstance("SHA");
			DigestInputStream din = new DigestInputStream(in, sha);
			@SuppressWarnings("unused")
			int b ;
			while((b=din.read())!=-1)
			{
			}
			din.close();
			byte[] digest = sha.digest();
			callback.receiveDigest(digest);
		}		
		catch (Exception e)
		{
		}
	}
	
}
